home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue47 / Clinic / NameSpc2U.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-06-01  |  4.8 KB  |  159 lines

  1. unit NameSpc2U;
  2.  
  3. {$ifdef Ver90} { Delphi 2.0x }
  4.   {$define DelphiLessThan3}
  5.   {$define DelphiLessThan4}
  6.   {$define DelphiLessThan5}
  7. {$endif}
  8. {$ifdef Ver93} { C++ Builder 1.0x }
  9.   {$define DelphiLessThan3}
  10.   {$define DelphiLessThan4}
  11.   {$define DelphiLessThan5}
  12. {$endif}
  13. {$ifdef Ver100} { Delphi 3.0x }
  14.   {$define DelphiLessThan4}
  15.   {$define DelphiLessThan5}
  16. {$endif}
  17. {$ifdef Ver110} { C++ Builder 3.0x }
  18.   {$define DelphiLessThan4}
  19.   {$define DelphiLessThan5}
  20. {$endif}
  21. {$ifdef Ver120} { Delphi 4.0x }
  22.   {$define DelphiLessThan5}
  23. {$endif}
  24. {$ifdef Ver125} { C++Builder 4.0x }
  25.   {$define DelphiLessThan5}
  26. {$endif}
  27.  
  28. interface
  29.  
  30. uses
  31.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  32.   StdCtrls, ComCtrls;
  33.  
  34. type
  35.   TForm1 = class(TForm)
  36.     btnInternetCache: TButton;
  37.     btnRecycledBin: TButton;
  38.     lstSpecialFolder: TListBox;
  39.     lvFolderContents: TListView;
  40.     procedure FormCreate(Sender: TObject);
  41.     procedure btnInternetCacheClick(Sender: TObject);
  42.     procedure btnRecycledBinClick(Sender: TObject);
  43.     procedure lstSpecialFolderClick(Sender: TObject);
  44.   end;
  45.  
  46. var
  47.   Form1: TForm1;
  48.  
  49. implementation
  50.  
  51. uses
  52. {$ifdef DelphiLessThan3}
  53.   OleAuto, Ole2,
  54. {$else}
  55.   ComObj,
  56. {$endif}
  57.   NameHlp2U, ShlObj;
  58.  
  59. {$R *.DFM}
  60.  
  61. {$ifdef DelphiLessThan4}
  62. const
  63.   CSIDL_INTERNET                  = $0001;
  64.   CSIDL_ALTSTARTUP                = $001d;         // DBCS
  65.   CSIDL_COMMON_ALTSTARTUP         = $001e;         // DBCS
  66.   CSIDL_COMMON_FAVORITES          = $001f;
  67.   CSIDL_INTERNET_CACHE            = $0020;
  68.   CSIDL_COOKIES                   = $0021;
  69.   CSIDL_HISTORY                   = $0022;
  70. {$endif}
  71. {$ifdef DelphiLessThan3}
  72. const
  73.   CSIDL_COMMON_STARTMENU          = $0016;
  74.   CSIDL_COMMON_PROGRAMS           = $0017;
  75.   CSIDL_COMMON_STARTUP            = $0018;
  76.   CSIDL_COMMON_DESKTOPDIRECTORY   = $0019;
  77.   CSIDL_APPDATA                   = $001a;
  78.   CSIDL_PRINTHOOD                 = $001b;
  79. {$endif}
  80.  
  81. type
  82.   TFolder = record
  83.     Name: String;
  84.     ID: Cardinal;
  85.   end;
  86. const
  87.   Folders: array[0..29] of TFolder = (
  88.     (Name: 'CSIDL_DESKTOP'; ID: CSIDL_DESKTOP),
  89.     (Name: 'CSIDL_INTERNET'; ID: CSIDL_INTERNET),
  90.     (Name: 'CSIDL_PROGRAMS'; ID: CSIDL_PROGRAMS),
  91.     (Name: 'CSIDL_CONTROLS'; ID: CSIDL_CONTROLS),
  92.     (Name: 'CSIDL_PRINTERS'; ID: CSIDL_PRINTERS),
  93.     (Name: 'CSIDL_PERSONAL'; ID: CSIDL_PERSONAL),
  94.     (Name: 'CSIDL_FAVORITES'; ID: CSIDL_FAVORITES),
  95.     (Name: 'CSIDL_STARTUP'; ID: CSIDL_STARTUP),
  96.     (Name: 'CSIDL_RECENT'; ID: CSIDL_RECENT),
  97.     (Name: 'CSIDL_SENDTO'; ID: CSIDL_SENDTO),
  98.     (Name: 'CSIDL_BITBUCKET'; ID: CSIDL_BITBUCKET),
  99.     (Name: 'CSIDL_STARTMENU'; ID: CSIDL_STARTMENU),
  100.     (Name: 'CSIDL_DESKTOPDIRECTORY'; ID: CSIDL_DESKTOPDIRECTORY),
  101.     (Name: 'CSIDL_DRIVES'; ID: CSIDL_DRIVES),
  102.     (Name: 'CSIDL_NETWORK'; ID: CSIDL_NETWORK),
  103.     (Name: 'CSIDL_NETHOOD'; ID: CSIDL_NETHOOD),
  104.     (Name: 'CSIDL_FONTS'; ID: CSIDL_FONTS),
  105.     (Name: 'CSIDL_TEMPLATES'; ID: CSIDL_TEMPLATES),
  106.     (Name: 'CSIDL_COMMON_STARTMENU'; ID: CSIDL_COMMON_STARTMENU),
  107.     (Name: 'CSIDL_COMMON_PROGRAMS'; ID: CSIDL_COMMON_PROGRAMS),
  108.     (Name: 'CSIDL_COMMON_STARTUP'; ID: CSIDL_COMMON_STARTUP),
  109.     (Name: 'CSIDL_COMMON_DESKTOPDIRECTORY'; ID: CSIDL_COMMON_DESKTOPDIRECTORY),
  110.     (Name: 'CSIDL_APPDATA'; ID: CSIDL_APPDATA),
  111.     (Name: 'CSIDL_PRINTHOOD'; ID: CSIDL_PRINTHOOD),
  112.     (Name: 'CSIDL_ALTSTARTUP'; ID: CSIDL_ALTSTARTUP),
  113.     (Name: 'CSIDL_COMMON_ALTSTARTUP'; ID: CSIDL_COMMON_ALTSTARTUP),
  114.     (Name: 'CSIDL_COMMON_FAVORITES'; ID: CSIDL_COMMON_FAVORITES),
  115.     (Name: 'CSIDL_INTERNET_CACHE'; ID: CSIDL_INTERNET_CACHE),
  116.     (Name: 'CSIDL_COOKIES'; ID: CSIDL_COOKIES),
  117.     (Name: 'CSIDL_HISTORY'; ID: CSIDL_HISTORY));
  118.  
  119. procedure TForm1.FormCreate(Sender: TObject);
  120. var
  121.   Loop: Cardinal;
  122. begin
  123.   for Loop := Low(Folders) to High(Folders) do
  124.     lstSpecialFolder.Items.AddObject(
  125.       Folders[Loop].Name, TObject(Folders[Loop].ID))
  126. end;
  127.  
  128. const
  129. {$ifdef DelphiLessThan3}
  130.   IID_InternetExplorerCache: TGUID = (
  131.     D1:$7BD29E00;D2:$76C1;D3:$11CF;D4:($9D,$D0,$00,$A0,$C9,$03,$49,$33));
  132.   IID_RecycleBin: TGUID = (
  133.     D1:$645FF040;D2:$5081;D3:$101B;D4:($9F,$08,$00,$AA,$00,$2F,$95,$4E));
  134. {$else}
  135.   IID_InternetExplorerCache: TGUID = '{7BD29E00-76C1-11CF-9DD0-00A0C9034933}';
  136.   IID_RecycleBin: TGUID = '{645FF040-5081-101B-9F08-00AA002F954E}';
  137. {$endif}
  138.  
  139. procedure TForm1.btnInternetCacheClick(Sender: TObject);
  140. begin
  141.   GetFolderItems(
  142.     CreateFolderObject(
  143.       GetSpecialFolderClsID('Cache')), lvFolderContents.Items)
  144. end;
  145.  
  146. procedure TForm1.btnRecycledBinClick(Sender: TObject);
  147. begin
  148.   GetFolderItems(
  149.     CreateFolderObject(IID_RecycleBin), lvFolderContents.Items)
  150. end;
  151.  
  152. procedure TForm1.lstSpecialFolderClick(Sender: TObject);
  153. begin
  154.   Caption := GetSpecialFolderLocation(
  155.     Cardinal(lstSpecialFolder.Items.Objects[lstSpecialFolder.ItemIndex]))
  156. end;
  157.  
  158. end.
  159.